#!/usr/local/bin/ruby
# Copyright (C) 2003-2010 Wang Pengcheng <wpc0000@gmail.com>
# , released under the MIT license
# You may obtain a template of the MIT License at
# http://www.opensource.org/licenses/mit-license.php
$KCODE = 'utf8'

require 'erb'
require 'es2utils'

file = ARGV[0]
result_filename = File.basename(file, '.txt')+'.tex'
# Get the Batch size
BANTCH_SIZE = Array.batch_size(ARGV[1])
puts 'Bantch Size='+BANTCH_SIZE.to_s

file_packets = FilePacket.new(file)

nwValues = file_packets.delay_results
puts 'Finish Calculate Delay time'
nwLossRate = file_packets.loss_rate_results
puts 'Finish Calculate Loss Rate'

def print_results(f, values)
  values.each do |delay|
    f.print delay[:path],':'
    datas = []
    delay[:ci][:data].each do |data|
      datas << data
    end
    f.puts datas.join(',')
  end
end

File.open('res_nn.txt','a') do |f|
  f.puts 'Delay time:'
  print_results(f, nwValues)
  f.puts 'Loss rate:'
  print_results(f, nwLossRate)
end

#template = ERB.new(File.read('templateS2.tex'))
#File.open(result_filename,'w')do |nf|
#  nf.puts template.result(binding)
#end

